<template>
  <div class="dv">
    <div class="dv1">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('form')"
            >立即创建</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
      <img src="../assets/logo.png" alt="" />
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: "", //用户名
        password: "", //密码
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
         
          this.$store.dispatch("login", this.form).then((res) => {
            console.log(res);
            if (res.data.meta.status == 200) {
              this.$router.push("/");
              this.$message({
                message: "恭喜你，跳转成功",
                type: "success",
              });
            }
          }); 
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
  created() {},
  mounted() {},
  components: {},
  computed: {},
  watch: {},
};
</script>

<style lang="scss" scoped>
.dv {
  background: #2b4b6b;
  width: 100vw;
  height: 100vh;

  overflow: hidden;
}
.dv .dv1 {
  width: 600px;
  height: 350px;
  background: #fff;
  margin: 200px auto 0;
  padding: 200px 0 0;
  position: relative;
}
img {
  position: absolute;
  left: 173px;
  top: -88px;
  border: 10px solid #ccc;
  border-radius: 50%;
}
</style>
